package com.mallbook.controller.servlet.front;

import com.mallbook.model.pojo.Category;
import com.mallbook.model.pojo.Goods;
import com.mallbook.model.service.CategoryService;
import com.mallbook.model.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author 宋明松
 * @Version V1.0.0
 * @Date 2022-07-04
 */
@WebServlet("/index")
public class IndexServlet extends HttpServlet {
    private GoodsService goodsService = new GoodsService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Goods> hotGoods = goodsService.getHotGoods(8);
        List<Goods> newGoods = goodsService.getNewGoods(8);
        req.setAttribute("hotGoods", hotGoods);
        req.setAttribute("newGoods", newGoods);
        InitBarUtils.getInitBar(req, resp); // 初始化导航栏
        req.getRequestDispatcher("/WEB-INF/front/index.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
